package com.guigu.liuzhireng.service.impl;

import com.guigu.liuzhireng.mapper.MenuMapper;
import com.guigu.liuzhireng.mapper.RolemenuMapper;
import com.guigu.liuzhireng.pojo.Menu;
import com.guigu.liuzhireng.pojo.Rolemenu;
import com.guigu.liuzhireng.service.RolemenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RolemenuServiceImpl implements RolemenuService {

    @Autowired
    RolemenuMapper rolemenuMapper;
    @Autowired
    MenuMapper menuMapper;

    @Override
    public List<Menu> RolemenuAll(Integer roleid) {
        List<Menu> roles = menuMapper.MenuAll(new Menu());
        List<Rolemenu> list = rolemenuMapper.list(roleid);

        for (Menu r : roles) {
            for (Rolemenu ar : list) {
                if (ar.getMenuid().equals(r.getMenuid())){
                    r.setTf(true);
                }
            }
        }
        return roles;
    }

    @Override
    public int DelAdd(List<Rolemenu> list, Integer roleid) {
        int deletes = rolemenuMapper.deletes(roleid);
        int inserts = rolemenuMapper.inserts(list);
        return deletes+inserts;
    }
}
